package com.xcity.game.buildv2;

import com.xcity.db.entity.Player;
import com.xcity.game.battle.pve.PVEManager;
import com.xcity.game.battle.pve.PVEStage;
import com.xcity.game.battle.pve.template.StageTemplate;
import com.xcity.game.buildv2.BuildV2.State;
import com.xcity.game.buildv2.template.BuildTemplateV2;

public class BuildUtils {
	
	public static boolean isUnlock(Player player, BuildV2 building) {
		if (building.getState() == null) {
			return isUnlock(player, building.getTemplate());
		}
		return building.getState() != State.LOCKED;
	}

	public static boolean isUnlock(Player player, BuildTemplateV2 template) {
		StageTemplate stageTemplate = template.getUnlockStage();
		if (stageTemplate == null) {
			return true;
		}
		PVEManager pve = player.getPveStages();
		if (pve == null) {
			return false;
		}
		PVEStage stage = pve.getStage(stageTemplate.getId());
		if (stage == null) {
			return false;
		}
		return stage.isPass();
	}
	
}
